//#pragma once

#ifndef __STRING_H__
#define __STRING_H__

#include <string.h>
#include <assert.h>

namespace dew
{
    class String
    {
    public:
        String(const char* str = "")
        {
            int len = strlen(str);

            _str = new char[len + 1];
            _capacity = len;
            _size = len;

            strcpy(_str,str);
        }

        ~String()
        {
            delete[] _str;
            _str = nullptr;
            _capacity = 0;
            _size = 0;
        }

        typedef char* iterator;
        typedef const char* const_iterator;

        iterator begin()
        {
            return _str;
        }

        iterator end()
        {
            return _str + _size;
        }


        size_t size() const
        {
            return _size;
        }

        size_t capacity() const
        {
            return _capacity;
        }

        char& operator[](size_t pos)
        {
            assert(pos <= _size);
            return _str[pos];
        }

        const char& operator[](size_t pos) const 
        {
            assert(pos <= _size);
            return _str[pos];
        }

        const char* c_str() const
        {
            return _str;
        }


    private:
        char* _str;
        size_t _size;
        size_t _capacity;
    };

}




#endif


